﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

namespace DAL
{
    public class RepairsDal : BaseDal<Model.Repairs>
    {
        public override string tablename
        {
            get { return "Repairs"; }
        }

        public override Dictionary<string, bool> PKName
        {
            get
            {

                Dictionary<string, bool> dic = new Dictionary<string, bool>();
                dic.Add("RepairsId", true);
                return dic;
            }
        }
        string str = ConfigurationManager.ConnectionStrings["db"].ConnectionString;
        /// <summary>
        /// 显示
        /// </summary>
        /// <param name="name"></param>
        /// <param name="date"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public List<Repairs> show(string name, string date, string state, string LogName)
        {
            using (SqlConnection con = new SqlConnection(str))
            {
                con.Open();
                string strsql = "select * from Repairs where RepairsName like '%" + name + "%' and convert(varchar,FindDate,23) like '%" + date + "%' and MaintainState like '%"+state+"%' and RapairsPeople='" + LogName + "'";
                SqlCommand cmd = new SqlCommand(strsql, con);
                SqlDataAdapter sat = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                sat.Fill(dt);
                List<Repairs> list = new List<Repairs>();
                foreach (DataRow i in dt.Rows)
                {
                    Repairs p = new Repairs();
                    p.RepairsId = Convert.ToInt32(i["RepairsId"]);
                    p.RailWayName = i["RailWayName"].ToString();
                    p.RepairsDesc = i["RepairsDesc"].ToString();
                    p.FindPeople = i["FindPeople"].ToString();
                    p.Grade = i["Grade"].ToString();
                    p.FindDate = (i["FindDate"]).ToString();
                    p.RapairsPicture = i["RapairsPicture"].ToString();
                    p.RapairsPeople = i["RapairsPeople"].ToString();
                    p.MaintainState = Convert.ToInt32(i["MaintainState"]);
                    p.ExamineState = Convert.ToInt32(i["ExamineState"]);
                    p.WangonName = i["WangonName"].ToString();
                    p.RepairsName = i["RepairsName"].ToString();
                    list.Add(p);
                }
                return list;
            }
        }

        /// <summary>
        /// 修改评价
        /// </summary>
        /// <returns></returns>
        public int updping(float star,string comments,int id)
        {
            using (SqlConnection con = new SqlConnection(str))
            {
                con.Open();
                string strsql = "update Repairs set star="+star+",comments='"+comments+"' where RepairsId="+id+"";
                SqlCommand cmd = new SqlCommand(strsql, con);
                return cmd.ExecuteNonQuery();
            }
        }
    }
}
